# Contributor: rubicon <rubicon@mailo.com>
# Maintainer: Celeste <cielesti@protonmail.com>
pkgname=ocaml-ppxlib
_pkgname=ppxlib
pkgver=0.32.0
pkgrel=0
pkgdesc="Standard library for ppx rewriters"
url="https://github.com/ocaml-ppx/ppxlib"
arch="all !riscv64 !loongarch64" # ocaml
license="MIT"
depends_dev="
	$pkgname=$pkgver-r$pkgrel
	ocaml-compiler-libs-repackaged-dev
	ocaml-ppx_derivers-dev
	ocaml-sexplib0-dev
	ocaml-stdlib-shims
	"
makedepends="$depends_dev dune ocaml"
checkdepends="
	ocaml-base-dev
	ocaml-cinaps-dev
	ocaml-findlib
	ocaml-re-dev
	ocaml-stdio-dev
	"
options="!check"
subpackages="$pkgname-dev"
source="$_pkgname-$pkgver.tar.bz2::https://github.com/ocaml-ppx/ppxlib/releases/download/$pkgver/ppxlib-$pkgver.tbz"
builddir="$srcdir/$_pkgname-$pkgver"
_ocamldir=usr/lib/ocaml

# 32-bit archs
case "$CARCH" in
	arm*|x86) options="$options textrels" ;;
esac

build() {
	dune build --release --verbose
}

check() {
	dune runtest --verbose
}

package() {
	dune install \
		--destdir="$pkgdir" \
		--docdir=/.omit
	rm -Rf "$pkgdir"/.omit
}

dev() {
	default_dev

	cd "$pkgdir"

	local path; find $_ocamldir \( \
			-name '*.cmt' -o \
			-name '*.cmti' -o \
			-name '*.ml' -o \
			-name '*.mli' \
		\) | while read -r path
	do
		amove "$path"
	done
}

prepare_py_provides() {
	local datadir="${subpkgdir:-$pkgdir}"
	local pkgbasedir=${pkgbasedir:-"$startdir/pkg"}
	local controldir="$pkgbasedir"/.control.${subpkgname:-$pkgname}

	options_has "!tracedeps" && return 0

	ocaml4-abuild-find provides \
		"$datadir"/usr/lib/ocaml \
		"$controldir" \
		"$pkgver-r$pkgrel"
}

scan_python3_dependency() {
	local controldir="$2" datadir="$3"

	ocaml4-abuild-find requires \
		"$datadir"/usr/lib/ocaml \
		"$controldir"
}

sha512sums="
73fef8ab8761bfbfde6ae87cc51eaacc5a5c937f0d628a890f0abdb2bffbf073932c25287a9e3baa2a1947c37f3dfa7f83ddd33c440e2e800971015addc97cd2  ppxlib-0.32.0.tar.bz2
"
